import java.util.ArrayList;
import java.util.List;

public class Manager extends User {
    private String name;
    private List<AnimalKeeper> animalKeepers = new ArrayList<>();
    private List<Animal> animals = new ArrayList<>();
    private List<Visitor> visitors = new ArrayList<>();

    public Manager(String name) {
        this.name = name;
    }

    // 管理饲养员
    public void addZookeeper(AnimalKeeper animalKeeper) {
        animalKeepers.add(animalKeeper);
    }

    public void removeZookeeper(AnimalKeeper animalKeeper) {
        animalKeepers.remove(animalKeeper);
    }

    public List<AnimalKeeper> getAnimalKeepers() {
        return animalKeepers;
    }

    public boolean addAnimalKeeper(AnimalKeeper animalKeeper) {
        return this.animalKeepers.add(animalKeeper);
    }

    public boolean deleteAnimalKeeper(AnimalKeeper animalKeeper) {
        return this.animalKeepers.remove(animalKeeper);
    }

    public boolean deleteAnimalKeeper(String animalKeeperName) {
        AnimalKeeper keeperToRemove = findAnimalKeeper(animalKeeperName);
        if (keeperToRemove != null) {
            return this.animalKeepers.remove(keeperToRemove);
        }
        return false;
    }

    public boolean updateAnimalKeeper(AnimalKeeper oldAnimalKeeper, AnimalKeeper newAnimalKeeper) {
        if (deleteAnimalKeeper(oldAnimalKeeper)) {
            return this.animalKeepers.add(newAnimalKeeper);
        }
        return false;
    }

    public AnimalKeeper findAnimalKeeper(String animalKeeperName) {
        for (AnimalKeeper animalKeeper : animalKeepers) {
            if (animalKeeper.getUserName().equals(animalKeeperName)) {
                return animalKeeper;
            }
        }
        return null;
    }

    // 管理动物
    public boolean addAnimal(Animal animal) {
        return this.animals.add(animal);
    }

    public boolean deleteAnimal(Animal animal) {
        return this.animals.remove(animal);
    }

    public boolean deleteAnimal(String animalName) {
        Animal animal = findAnimal(animalName);
        if (animal != null) {
            return this.animals.remove(animal);
        }
        return false;
    }

    public boolean updateAnimal(Animal oldAnimal, Animal newAnimal) {
        if (deleteAnimal(oldAnimal)) {
            return this.animals.add(newAnimal);
        }
        return false;
    }

    public Animal findAnimal(String animalName) {
        for (Animal animal : animals) {
            if (animal.getUserName().equals(animalName)) {
                return animal;
            }
        }
        return null;
    }

    public List<Animal> getAnimals() {
        return animals;
    }

    // 管理游客
    public boolean addVisitor(Visitor visitor) {
        return this.visitors.add(visitor);
    }

    public boolean deleteVisitor(Visitor visitor) {
        return this.visitors.remove(visitor);
    }

    public boolean deleteVisitor(String visitorName) {
        Visitor visitorToRemove = findVisitor(visitorName);
        if (visitorToRemove != null) {
            return this.visitors.remove(visitorToRemove);
        }
        return false;
    }

    public boolean updateVisitor(Visitor oldVisitor, Visitor newVisitor) {
        if (deleteVisitor(oldVisitor)) {
            return this.visitors.add(newVisitor);
        }
        return false;
    }

    public Visitor findVisitor(String visitorName) {
        for (Visitor visitor : visitors) {
            if (visitor.getUserName().equals(visitorName)) {
                return visitor;
            }
        }
        return null;
    }

    public List<Visitor> getVisitors() {
        return visitors;
    }

    public String displayAllAnimalKeepers() {
        StringBuilder displayMessage = new StringBuilder();
        for (AnimalKeeper animalKeeper : this.animalKeepers) {
            displayMessage.append(animalKeeper.getUserName()).append("\n");
        }
        return displayMessage.toString();
    }

    public String displayAllAnimals() {
        StringBuilder displayMessage = new StringBuilder();
        for (Animal animal : this.animals) {
            displayMessage.append(animal.getUserName()).append("\n");
        }
        return displayMessage.toString();
    }

    public String displayAllVisitors() {
        StringBuilder displayMessage = new StringBuilder();
        for (Visitor visitor : this.visitors) {
            displayMessage.append(visitor.getUserName()).append("\n");
        }
        return displayMessage.toString();
    }
}
